# Integrates powertabdocument.cpp and powertabobject.cpp / powertabdocument.php
# Loads and saves Power Tab files (.ptb) and provides support for polymorphic reading/writing of Power Tab objects

# Last update: 080629 RH

#require 'macros'
#require 'systemsymbol'
#require 'alternateending'
#require 'barline'
#require 'chorddiagram'
#require 'chordname'
#require 'chordtext'
#require 'direction'
#require 'dynamic'
#require 'floatingtext'
require 'fontsetting'
#require 'generalmidi'
require 'guitar'
require 'guitarin'
#require 'keysignature'
#require 'note'
#require 'position'
require 'powertabfileheader'
#require 'powertabinputstream'
#require 'powertaboutputstream'
#require 'powertabstream'
#require 'rehearsalsign'
#require 'rhythmslash'
require 'score'
#require 'staff'
require 'system'
#require 'tempomarker'
#require 'timesignature'
#require 'tuning'

NUM_DOCUMENT_FONT_SETTINGS = 3
DOCUMENT_FONT_SETTING_CHORD_NAME = 0
DOCUMENT_FONT_SETTING_TABLATURE_NUMBERS = 1
DOCUMENT_FONT_LYRICS = 2

class PowerTabDocument
	
  attr_reader :m_header
  attr_accessor :m_fade_in
  attr_accessor :m_fade_out

  # Constants
  DEFAULT_TABLATURE_STAFF_LINE_SPACING = 9
  DEFAULT_FADE_IN = 0
  DEFAULT_FADE_OUT = 0
 
  MIN_TABLATURE_STAFF_LINE_SPACING = 6
  MAX_TABLATURE_STAFF_LINE_SPACING = 14
 
  NUM_SCORES = 2
  GUITAR_SCORE = 0
  BASS_SCORE = 1
 
  MAX_GUITARS = 7

  # Constructor
  def initialize

    @m_header = PowerTabFileHeader.new
    @m_score_array[0] = Score.new
    @m_score_array[1] = Score.new

    NUM_DOCUMENT_FONT_SETTINGS.times do |font_setting_index|
      @m_font_setting_array[font_setting_index] = FontSetting.new    
    
    @m_fade_out = DEFAULT_FADE_OUT
	
  end  
  
  # Load methods
  
  def load(file_name)
  
  end

  def load_file(stream)
  
  end

  def load_object(stream)

    @m_header.deserialize(stream)
    
    # Considering v1.7 only at the beginning
    version = @m_header.get_version
    deserialize_format_1_7(stream)
    
  end
  
  # Deserialization methods
  
  def deserialize_format_1_7(stream)

    version = PowerTabFileHeader::FILEVERSION_1_7

    @m_score_array[0] = Score.new
    @m_score_array[0].do_deserialize(stream)

    @m_score_array[1] = Score.new    
    @m_score_array[1].do_deserialize(stream)

    NUM_DOCUMENT_FONT_SETTINGS.times do |font_setting_index|
      font_setting = FontSetting.new    
      font_setting.do_deserialize(stream)
      @m_font_setting_array[font_setting_index] = font_setting    

    @m_tablatureStaffLineSpacing = read_signed_integer(stream)
    @m_fade_in = read_integer(stream)
    @m_fade_out = read_integer(stream)

  end
  
  # Save methods
  
  def save(file_name)
  
  end
  
  def save_object(stream)
  
  end
  
  # Other methods
  
  def delete_score_array_contents
  
  end
	    
end